package com.blrs.service.teacherInfo.impl;

import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.blrs.common.annotation.DataScope;
import com.blrs.common.utils.ReflectionUtils;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.StringUtils;
import com.blrs.common.utils.uuid.UUID;
import com.blrs.service.teacherInfo.ITeacherInfoService;
import com.blrs.system.mapper.SysUploadFileMapper;
import com.blrs.system.service.ISysDeptService;
import org.jsoup.Jsoup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.mapper.TeacherInfoMapper;
import com.blrs.domain.TeacherInfo;


/**
 * 师资管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-17
 */
@Service
public class TeacherInfoServiceImpl implements ITeacherInfoService
{
    @Autowired
    private TeacherInfoMapper teacherInfoMapper;
    @Autowired
    private SysUploadFileMapper sysUploadFileMapper;
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询师资管理
     * 
     * @param id 师资管理主键
     * @return 师资管理
     */
    @Override
     public TeacherInfo selectTeacherInfoById(String id)
    {
        TeacherInfo teacherInfo = teacherInfoMapper.selectTeacherInfoById(id);
        teacherInfo.setFileUrl(sysUploadFileMapper.selectUrlByCode("teacherInfo",teacherInfo.getUploadFile()));
        return teacherInfo;
    }

    /**
     * 查询师资管理列表
     * 
     * @param teacherInfo 师资管理
     * @return 师资管理
     */
    @Override
    @DataScope(deptAlias = "t",userAlias = "t")
    public List<TeacherInfo> selectTeacherInfoList(TeacherInfo teacherInfo)
    {
        teacherInfo.setOrganizationId(SecurityUtils.getOrgId());
        List<TeacherInfo> teacherInfos = teacherInfoMapper.selectTeacherInfoList(teacherInfo);
       teacherInfos.stream()
              .forEach(teacherInfo1 -> {
                  if (StringUtils.isNotEmpty(teacherInfo1.getUploadFile())) {
                      teacherInfo1.setFileUrl(sysUploadFileMapper.selectUrl(teacherInfo1.getUploadFile()));
                  }
              });
     return teacherInfos;
    }
    public String removeHtmlTags(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }
        return Jsoup.parse(input).text();
    }
    @Override
    public List<TeacherInfo> selectTeacherInfoListExport(TeacherInfo teacherInfo) {
        teacherInfo.setOrganizationId(SecurityUtils.getOrgId());
        List<TeacherInfo> teacherInfos = teacherInfoMapper.selectTeacherInfoListExport(teacherInfo);
        teacherInfos.stream()
                .forEach(teacherInfo1 -> {
                    teacherInfo1.setSpeciality(removeHtmlTags(teacherInfo1.getSpeciality()));
                    teacherInfo1.setCourse(removeHtmlTags(teacherInfo1.getCourse()));
                    teacherInfo1.setServicePrices(removeHtmlTags(teacherInfo1.getServicePrices()));
                    teacherInfo1.setWorkExperience(removeHtmlTags(teacherInfo1.getWorkExperience()));
                    teacherInfo1.setQualification(removeHtmlTags(teacherInfo1.getQualification()));
                    if (StringUtils.isNotEmpty(teacherInfo1.getUploadFile())) {
                        teacherInfo1.setFileUrl(sysUploadFileMapper.selectUrl(teacherInfo1.getUploadFile()));
                    }
                });
        return teacherInfos;
    }

    /**
     * 新增师资管理
     * 
     * @param teacherInfo 师资管理
     * @return 结果
     */
    @Override
    public int insertTeacherInfo(TeacherInfo teacherInfo) throws NoSuchFieldException, IllegalAccessException {
        ReflectionUtils.setCommonPrivateProperty(teacherInfo);
        teacherInfo.setOrganizationId(SecurityUtils.getOrgId());
        teacherInfo.setOrganizationName(SecurityUtils.getOrgName());
        teacherInfo.setCreateId(SecurityUtils.getUserId());
        return teacherInfoMapper.insertTeacherInfo(teacherInfo);
    }

    /**
     * 修改师资管理
     * 
     * @param teacherInfo 师资管理
     * @return 结果
     */
    @Override
    public int updateTeacherInfo(TeacherInfo teacherInfo)
    {
        teacherInfo.setOperateTime(new Date());
        return teacherInfoMapper.updateTeacherInfo(teacherInfo);
    }

    /**
     * 批量删除师资管理
     * 
     * @param ids 需要删除的师资管理主键
     * @return 结果
     */
    @Override
    public int deleteTeacherInfoByIds(String[] ids)
    {
        return teacherInfoMapper.deleteTeacherInfoByIds(ids);
    }

    /**
     * 删除师资管理信息
     * 
     * @param id 师资管理主键
     * @return 结果
     */
    @Override
    public int deleteTeacherInfoById(String id)
    {
        return teacherInfoMapper.deleteTeacherInfoById(id);
    }

    @Override
    public int selectTeacherInfoNumber(Long organizationId) {
        return teacherInfoMapper.selectTeacherInfoNumber(organizationId);
    }


    public static void main(String[] args) {
        String string = UUID.fastUUID().toString().split("-").toString();
        System.out.println(string);
    }
}
